package com.gxgeek.javabasic.javakeywords.volatiles;

/**
 * Created by GX on 2017/8/30.
 */
//@Slf4j
public class VolatileExampleTwo extends Thread{
    //设置类静态变量,各线程访问这同一共享变量
    private  static  boolean flag = false;
    private  static        long num = 10000000000L;
    //无限循环,等待flag变为true时才跳出循环
    public void run() {
        while (!flag){
            if (num<10){
                System.out.println(num);
            }
//            System.out.println(num);
//            log.info(String.valueOf(num));
        };
        System.out.println(num);
//        log.info("停止了");
    }

    public static void main(String[] args) throws Exception {
        new VolatileExampleTwo().start();
        //sleep的目的是等待线程启动完毕,也就是说进入run的无限循环体了
        Thread.sleep(100);
        num = 8;
//        num = 963.485;
//        Thread.sleep(1);
        flag = true;
    }

    //  5
//      5.65
  //    5.65

}
